using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.UI;

public class TipBg : MonoBehaviour
{
    public Image headImage;
    public Text nameText;
    public Text levelText;
    public Text talentDescText;
    private const string KEY = "PersonLevel_";

    public void SetData()
    {
        int currentIndex = PlayerPrefs.GetInt("CharacterCurrentIndex");
        JObject data = Data.touxiangpeizhi[currentIndex].ToObject<JObject>();
        int lv = GetPersonLevel(currentIndex);

        if (data == null) return;
        nameText.text = data["name"].ToString();
        headImage.sprite = ResManager.Instance.GetHeadIcons()[currentIndex];
        string desc = data["talent"].ToString();
        string newDesc = desc.Replace("{{talent_value}}", data["talent_value"][lv - 1].ToString());
        talentDescText.text = newDesc;


        levelText.text = $"lv.{lv}";
    }

    public int GetPersonLevel(int index)
    {
        return PlayerPrefs.GetInt(KEY + index, 1);
    }
}
